package com.mgq.juc.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author MaGuangQi
 * 测试jdk Fixed线程池
 * return new ThreadPoolExecutor(nThreads, nThreads,
 *                                       0L, TimeUnit.MILLISECONDS,
 *                                       new LinkedBlockingQueue<Runnable>());
 *
 *Fixed线程池特点:
 * 1.核心线程数=最大线程数
 * 2.没有救急线程
 * 3.使用的是无界队列
 * @date 2021-12-22 09:37
 **/
@Slf4j
public class TestJdkFixedThreadPool {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        executorService.execute(()->{
            log.debug("begin");
            log.debug("1");
            int i=2/0;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("end");
        });
        executorService.execute(()->{
            log.debug("begin");
            log.debug("2");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("end");
        });
        executorService.execute(()->{
            log.debug("begin");
            log.debug("3");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("end");
        });
    }
}
